Page({
    data: {
      avatarUrl: 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132',
      nickName: '',
      stats: {
        posts: 0,
        cooperation: 1,
        collections: 0
      },
      menuItems: [
        {
          id: 1,
          icon: '/images/icons/verify.png',
          iconBg: '#e3f2fd',
          text: '我的认证'
        },
        {
          id: 2,
          icon: '/images/icons/book.png',
          iconBg: '#e8f5e9',
          text: '我的背书'
        },
        {
          id: 3,
          icon: '/images/icons/message.png',
          iconBg: '#fff3e0',
          text: '我的消息'
        },
        {
          id: 4,
          icon: '/images/icons/feedback.png',
          iconBg: '#f3e5f5',
          text: '反馈与投诉'
        },
        {
          id: 5,
          icon: '/images/icons/settings.png',
          iconBg: '#e0f2f1',
          text: '设置'
        }
      ]
    },
  
    onLoad() {
      this.loadUserInfo()
    },
    onShow(){
      this.loadIndexData()
    },
  // 预览头像
  previewAvatar() {
    wx.previewImage({
      current: this.data.avatarUrl, // 当前显示图片的http链接
      urls: [this.data.avatarUrl] // 需要预览的图片http链接列表
    })
  },
  //记载我的发布 合作等基本信息
    loadIndexData(){
      const userId = wx.getStorageSync('userId')
      wx.request({
        url: 'http://a1.iwmls.com/index/wode/index ',
        method: 'POST',
        data: {
          uid: userId
        },success: (res) => {
          console.log(res.data)
        }
      })
    },
    // 加载用户信息
    loadUserInfo() {
      // TODO: 实现用户数据加载逻辑
      const userId =  wx.getStorageSync('userId')
      wx.request({
        url: 'http://a1.iwmls.com/index/wode/selectuser',
        method: 'GET',
        data: {
          id: userId
        },success: (res) => {
          //设置头像和昵称
          this.setData({
            avatarUrl: res.data.data.avatarurl,
            nickName: res.data.data.nickname
          })
        }
      })
    
    },
  
    // 处理菜单项点击
    handleMenuClick(e) {
      const id = e.currentTarget.dataset.id
      // TODO: 实现菜单跳转逻辑
      switch (id) {
        case 1:
            wx.navigateTo({
                url: '/pages/authentication/authentication' 
            });
            break;
        case 2:
            wx.navigateTo({
                url: '/pages/page2/page2' // 替换为实际的页面路径
            });
            break;
        case 3:
            wx.navigateTo({
                url: '/pages/page3/page3' // 替换为实际的页面路径
            });
            break;
        default:
            console.log('未匹配到对应的页面跳转规则');
    }
    },
  
    // 处理退出登录
    handleLogout() {
      wx.showModal({
        title: '提示',
        content: '确定要退出登录吗？',
        success: (res) => {
          wx.removeStorageSync('userId')
        }
      })
    }
  })